package com.wenhui.schoolyardinfo.firstpage.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.wenhui.schoolyardinfo.R;
import com.wenhui.schoolyardinfo.base.BaseFragment;
import com.wenhui.schoolyardinfo.firstpage.adapter.BaseRecyclerAdapter;
import com.wenhui.schoolyardinfo.firstpage.bean.PhotoBean;
import com.wenhui.schoolyardinfo.firstpage.bean.MineAlbumBean;
import com.wenhui.schoolyardinfo.firstpage.holder.SmartViewContentHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * author    : Urasaki
 * e-mail    : 1164688204@qq.com
 * date      : 2019/6/17 09:45
 * introduce :
 */

public class AlbumFragment extends BaseFragment {

    private static final String TAG = "AlbumFragment";
    @BindView(R.id.mine_recycler_view)
    RecyclerView mineRecyclerView;
    Unbinder unbinder;

    private BaseRecyclerAdapter<MineAlbumBean> baseRecyclerAdapter;
    private List<PhotoBean> photoBeanList;
    private List<MineAlbumBean> mineAlbumBeanList;
    private GridLayoutManager layoutManager;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_photo_album, container, false);
        unbinder = ButterKnife.bind(this, view);

        initData();
        initViews();
        return view;
    }

    @Override
    protected void initData() {
        photoBeanList = new ArrayList<>();
        mineAlbumBeanList = new ArrayList<>();
        photoBeanList.add(new PhotoBean(0, "校园", "http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg", false));
        photoBeanList.add(new PhotoBean(0, "校园", "http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg", false));
        photoBeanList.add(new PhotoBean(0, "校园", "http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg", false));
        photoBeanList.add(new PhotoBean(0, "校园", "http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg", false));
        photoBeanList.add(new PhotoBean(0, "校园", "http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg", false));
        photoBeanList.add(new PhotoBean(0, "校园", "http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg", false));

        mineAlbumBeanList.add(new MineAlbumBean("隆美尔上将相册", 199,
                photoBeanList, "所有人可见"));
        mineAlbumBeanList.add(new MineAlbumBean("隆美尔上将相册", 199,
                photoBeanList, "所有人可见"));
        mineAlbumBeanList.add(new MineAlbumBean("隆美尔上将相册", 199,
                photoBeanList, "所有人可见"));
        mineAlbumBeanList.add(new MineAlbumBean("隆美尔上将相册", 199,
                photoBeanList, "所有人可见"));
        mineAlbumBeanList.add(new MineAlbumBean("隆美尔上将相册", 199,
                photoBeanList, "所有人可见"));
        mineAlbumBeanList.add(new MineAlbumBean("隆美尔上将相册", 199,
                photoBeanList, "所有人可见"));

    }

    @Override
    protected void initViews() {
        layoutManager = new GridLayoutManager(getActivity(), 2);
//        layoutManager.setOrientation(OrientationHelper.VERTICAL);

        mineRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mineRecyclerView.setLayoutManager(layoutManager);
        baseRecyclerAdapter = new BaseRecyclerAdapter<MineAlbumBean>(R.layout.item_mine_album_content, 1) {
            @Override
            protected void onBindViewHolder(RecyclerView.ViewHolder holder, MineAlbumBean model, int position) {
                if (holder instanceof SmartViewContentHolder) {
                    SmartViewContentHolder smartViewContentHolder = (SmartViewContentHolder) holder;
                    Glide.with(getActivity())
                            .load(model.getPhotoBeanList().get(0).getPhotoUrl())
                            .into((ImageView) smartViewContentHolder.getView(R.id.imv_photo_album));
                    smartViewContentHolder.text(R.id.tev_photo_album_name, model.getAlbumName());
                    smartViewContentHolder.text(R.id.tev_photo_album_num, model.getPhotoNum() + "张");
                    smartViewContentHolder.text(R.id.tev_photo_album_jurisdiction, model.getAlbumJurisdiction());
                }
            }
        };
        mineRecyclerView.setAdapter(baseRecyclerAdapter);

        baseRecyclerAdapter.clearData();
        baseRecyclerAdapter.addAllData(mineAlbumBeanList);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
